package com.example.login.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.book.entity.Type;
import com.example.common.dtos.ResponseResult;
import com.example.login.entity.Employee;
import com.example.login.service.EmployeeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/employee")
@Api(tags = "员工控制器")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    /**
     * 员工登录
     * @param
     * @param employee
     * @return
     */
    @ApiOperation(value = "员工登录")
    @PostMapping("/login")
    public ResponseResult login(@RequestBody Employee employee){
        return employeeService.getEmployee(employee);
    }

    /**
     * 退出
     * @return
     */
    @ApiOperation(value = "退出")
    @PostMapping("logout")
    public ResponseResult logout(){
        employeeService.logout();
        return ResponseResult.okResult("退出登陆成功");
    }

    /**
     * 查询员工信息
     * @param page
     * @param pageSize
     * @param name
     * @return
     */
    @ApiOperation(value = "查询员工信息")
    @GetMapping("/page")
    public ResponseResult<Page> page(Integer page, Integer pageSize, String name) {

        return employeeService.pageInfo(page, pageSize, name);
    }

    /**
     * 添加员工
     * @param employee
     * @return
     */
    @ApiOperation(value = "添加员工")
    @PostMapping
    public ResponseResult add(@RequestBody Employee employee){
        return employeeService.addEmployee(employee);
    }

    /**
     * 数据回显
     * @param id
     * @return
     */
    @ApiOperation(value = "数据回显")
    @GetMapping("/{id}")
    public ResponseResult type(@PathVariable Long id){
        return employeeService.employee(id);
    }

    /**
     * 修改方法
     * @param employee
     * @return
     */
    @ApiOperation(value = "修改方法")
    @PutMapping
    public ResponseResult<String> update(@RequestBody Employee employee){
        log.info("修改图书标签信息:{}",employee);
        employeeService.updateById(employee);
        return ResponseResult.okResult("修改图书标签成功");
    }

    /**
     * 修改状态
     *
     * @param
     * @return
     */
    @ApiOperation(value = "修改状态")
    @PutMapping("/status")
    public ResponseResult status(Long id) {
        return ResponseResult.okResult(employeeService.updateStatus(id));
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @ApiOperation(value = "删除")
    @DeleteMapping
    public ResponseResult delete(Long [] ids) {
        return employeeService.deleteEmployees(ids);
    }
}
